package com.infocollect.project.grant.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.infocollect.framework.aspectj.lang.annotation.Log;
import com.infocollect.framework.aspectj.lang.enums.BusinessType;
import com.infocollect.project.grant.domain.GrUserCompany;
import com.infocollect.project.grant.service.IGrUserCompanyService;
import com.infocollect.framework.web.controller.BaseController;
import com.infocollect.framework.web.domain.AjaxResult;
import com.infocollect.common.utils.poi.ExcelUtil;
import com.infocollect.framework.web.page.TableDataInfo;

/**
 * 派出单位用户Controller
 * 
 * @author infocollect
 * @date 2022-06-12
 */
@RestController
@RequestMapping("/grant/userCompany")
public class GrUserCompanyController extends BaseController
{
    @Autowired
    private IGrUserCompanyService grUserCompanyService;

    /**
     * 查询派出单位用户列表
     */
    @PreAuthorize("@ss.hasPermi('grant:userCompany:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrUserCompany grUserCompany)
    {
        startPage();
        List<GrUserCompany> list = grUserCompanyService.selectGrUserCompanyList(grUserCompany);
        return getDataTable(list);
    }

    /**
     * 导出派出单位用户列表
     */
    @PreAuthorize("@ss.hasPermi('grant:userCompany:export')")
    @Log(title = "派出单位用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GrUserCompany grUserCompany)
    {
        List<GrUserCompany> list = grUserCompanyService.selectGrUserCompanyList(grUserCompany);
        ExcelUtil<GrUserCompany> util = new ExcelUtil<GrUserCompany>(GrUserCompany.class);
        return util.exportExcel(list, "userCompany");
    }

    /**
     * 获取派出单位用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('grant:userCompany:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(grUserCompanyService.selectGrUserCompanyById(id));
    }

    /**
     * 新增派出单位用户
     */
    @PreAuthorize("@ss.hasPermi('grant:userCompany:add')")
    @Log(title = "派出单位用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrUserCompany grUserCompany)
    {
        return toAjax(grUserCompanyService.insertGrUserCompany(grUserCompany));
    }

    /**
     * 修改派出单位用户
     */
    @PreAuthorize("@ss.hasPermi('grant:userCompany:edit')")
    @Log(title = "派出单位用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrUserCompany grUserCompany)
    {
        return toAjax(grUserCompanyService.updateGrUserCompany(grUserCompany));
    }

    /**
     * 删除派出单位用户
     */
    @PreAuthorize("@ss.hasPermi('grant:userCompany:remove')")
    @Log(title = "派出单位用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(grUserCompanyService.deleteGrUserCompanyByIds(ids));
    }
}
